import 'package:flutter/material.dart';
import 'package:flutter_massage/common_lib/extension/ex_widget.dart';
import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/common_lib/routers/route.dart';
import 'package:flutter_massage/common_lib/ui/common_component.dart';
import 'package:flutter_massage/pages/home/home_component.dart';
import 'package:flutter_massage/pages/model/bean.dart';
import 'package:flutter_massage/pages/preject/detail/project_detail_page.dart';
import 'package:flutter_massage/pages/technician/store_detail/store_detail_logic.dart';
import 'package:flutter_massage/pages/technician/technician_list/technician_list_page.dart';
import 'package:flutter_massage/service/index.dart';
import 'package:flutter_massage/values/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class StoreDetailPage extends GetView<StoreDetailLogic> {
  const StoreDetailPage(this.bean, {super.key});

  final Shop bean;

  @override
  Widget build(BuildContext context) {
    return BaseScaffold(
      titleStr: '店铺详情',
      scaffoldBackgroundColor: AppColors.grayF8,
      child: GetBuilder<StoreDetailLogic>(
        init: StoreDetailLogic(bean),
        assignId: true,
        builder: (logic) {
          return SingleChildScrollView(
            padding: EdgeInsets.all(12.w),
            child: Column(
              children: [
                StoreDetailInfo(bean),
                StoreDetailTechnician(bean).paddingTop(16.w),
                StoreDetailProject(bean).paddingTop(16.w),
              ],
            ),
          );
        },
      ),
    );
  }
}

class StoreDetailInfo extends StatelessWidget {
  const StoreDetailInfo(this.bean, {super.key});

  final Shop bean;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            TextWidget.oneLine(
              text: bean.shopName ?? '',
              fontSize: 16,
              color: AppColors.textLevelOne,
              fontWeight: FontWeight.bold,
            ).expanded(),
            // ButtonWidget.iconText(
            //   Assets.svgLocationGreen.toSvg(width: 13.w),
            //   bean.distance ?? '',
            //   fontSize: 13,
            //   textColor: AppColors.primaryGreen,
            //   spacing: 2.w,
            //   hasInkWell: false,
            // ).paddingLeft(5.w),
          ],
        ),
        CommonMargin.height(4.w),
        Row(
          children: [
            Text.rich(
              TextSpan(
                text: '评分：',
                children: [
                  TextSpan(text: bean.shopScore ?? '', style: const TextStyle(color: AppColors.primaryOrange)),
                ],
                style: TextStyle(fontSize: 12, color: '#66737F'.toColor, fontWeight: FontWeight.bold),
              ),
            ),
            CommonMargin.width(16.w),
            Text.rich(
              TextSpan(
                text: '已服务人次：',
                children: [
                  TextSpan(
                      text: (bean.servedNum ?? 0).toString(), style: const TextStyle(color: AppColors.primaryOrange)),
                ],
                style: TextStyle(fontSize: 12, color: '#66737F'.toColor, fontWeight: FontWeight.bold),
              ),
            ).flexible(),
          ],
        ),
      ],
    ).card(radius: 8.w, padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 16.w));
  }
}

class StoreDetailTechnician extends StatelessWidget {
  const StoreDetailTechnician(this.bean, {super.key});

  final Shop bean;

  @override
  Widget build(BuildContext context) {
    List<TechnicianBean> lists = bean.shopTechnicians ?? [];
    if (lists.isEmpty) return Container();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CommonTitleComponent(
            title: '技师列表',
            onTapAll: () async {
              var result = await JsonService.getTechnicianList();
              CommonRoute.open(TechnicianListPage(result));
            }),
        Column(
          children: List.generate(
            lists.length,
            (index) => CommonTechnicianItem(lists[index]).paddingBottom(12.w),
          ),
        ).paddingTop(12.w),
      ],
    );
  }
}

class StoreDetailProject extends StatelessWidget {
  const StoreDetailProject(this.bean, {super.key});

  final Shop bean;

  @override
  Widget build(BuildContext context) {
    List<ProjectBean> lists = bean.shopServiceItems ?? [];
    if (lists.isEmpty) return Container();

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const CommonTitleComponent(title: '服务项目'),
        Column(
          children: lists.map((e) => HomeRecommendProject(e).paddingBottom(12.w)).toList(),
        ).paddingTop(12.w),
      ],
    );
  }
}
